//
//  YKFarmFarmAddController.m
//  YK_BaseMediator
//
//  Created by edward on 2021/3/12.
//  Copyright © 2021 Edward. All rights reserved.
//

#import "YKFarmFarmAddController.h"
#import <Masonry/Masonry.h>
#import <YK_ExectionModel/YKNSObjectCore.h>
#import <YK_ExectionModel/YKUIKitCore.h>

@interface YKFarmFarmAddController ()

///
@property(nonatomic,copy) void(^nameBlock)(NSString *name);
///
@property(nonatomic,strong) UITextField *nameTextField;
@end

@implementation YKFarmFarmAddController

- (instancetype)initWithBlock:(void(^)(NSString *name))block
{
    if (self = [super init]) {
        self.title = @"创建农场";
        self.nameBlock = block;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIView *topView = UIView.instance.yk_borderColor(UIColor.blackColor);
    [self.view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(44);
    }];
    UILabel *titleLabel = UILabel.instance;
    titleLabel.text = self.title;
    titleLabel.font = [UIFont systemFontOfSize:20];
    [topView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(topView.mas_centerY);
        make.centerX.mas_equalTo(topView.mas_centerX);
    }];
    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton setTitleColor:UIColor.blueColor forState:UIControlStateNormal];
    [topView addSubview:cancelButton];
    [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(44);
    }];
    UIButton *comfirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [comfirmButton setTitle:@"确定" forState:UIControlStateNormal];
    [comfirmButton setTitleColor:UIColor.blueColor forState:UIControlStateNormal];
    [topView addSubview:comfirmButton];
    [comfirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.mas_equalTo(0);
        make.width.mas_equalTo(44);
    }];
    
    UILabel *nameLb = UILabel.instance;
    nameLb.text = @"农场名:";
    nameLb.font = [UIFont systemFontOfSize:20];
    nameLb.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:nameLb];
    [nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).offset(10);
        make.top.mas_equalTo(topView.mas_bottom).offset(10);
        make.width.mas_equalTo((YKScreenW - 20)/2);
        make.height.mas_equalTo(24);
    }];
    [self.view addSubview:self.nameTextField];
    [self.nameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(nameLb.mas_top);
        make.left.mas_equalTo(nameLb.mas_right);
        make.right.mas_equalTo(self.view.mas_right).offset(-10);
        make.width.mas_equalTo(nameLb.mas_width);
        make.height.mas_equalTo(nameLb.mas_height);
    }];
    
    
    @weakify(self);
    [[cancelButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
    [[comfirmButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        if (self.nameBlock) {
            self.nameBlock(self.nameTextField.text);
        }
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
}


- (UITextField *)nameTextField
{
    if (!_nameTextField) {
        _nameTextField = (UITextField *)[[UITextField alloc] init].yk_borderColor(UIColor.blackColor);
        
    }
    return _nameTextField;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
